<?php
namespace App\Http\Controllers;

use App\Http\Controllers\WebController;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Business\ValveModule;

class ValveController extends WebController
{
    //
    public function valveList() {
        $result = ValveModule::valveList(1, 50);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        return view('valve.valve_list', $data);
    }
    public function valveAdd() {
        return view('valve.valve_add');
    }
    public function submitValveAddData() {
        $name = $this->request->get('name');
        $number = $this->request->get('number');
        $caliber = $this->request->get('caliber');
        $area = $this->request->get('area');
        $longitude = $this->request->get('longitude');
        $latitude = $this->request->get('latitude');
        $fatherNode = $this->request->get('father_node');
        $result = ValveModule::addValve($number, $name, $caliber, $area, $longitude,$latitude, $fatherNode);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessMessage($result['message']);
    }
    public function valveGet() {
        $id = $this->request->get('id');
        $result = ValveModule::getValve($id);
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];
        return view('valve.valve_add', $data);
    }
    public function valveEdit() {
        $id = $this->request->get('id');
        $name = $this->request->get('name');
        $caliber = $this->request->get('caliber');
        $area = $this->request->get('area');
        $longitude = $this->request->get('longitude');
        $latitude = $this->request->get('latitude');
        $fatherNode = $this->request->get('father_node');
        $result = ValveModule::editValve($id, $name, $caliber, $area, $latitude, $longitude, $fatherNode);
        if($result['status'] == 'failed'){
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessMessage($result['message']);
    }
    public function valveTree() {
        $result  = ValveModule::cancerHospitalTree();
        if($result['status'] == 'failed') {
            return view('errors.404');
        }
        $data = $result['data'];

        return view('valve.valve_tree',$data);
    }
}